package com.diandiansong.manager.ui.biz;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.diandiansong.app.R;
import com.diandiansong.manager.entity.SalesUserCustomerInfo;
import com.diandiansong.manager.entity.SalesUsercustomer_viewInfo;
import com.diandiansong.manager.utils.M;

import butterknife.BindView;
import butterknife.OnClick;
import diandiansong.library.ui.base.BaseAct;
import diandiansong.library.utils.CCallBack;
import diandiansong.library.utils.ImgLoader;

/**
 * 我的客户详情
 */
public class CustomerDetail extends BaseAct {

    static SalesUserCustomerInfo.Data mData;
    @BindView(R.id.iv_avatar)
    ImageView mIvAvatar;
    @BindView(R.id.tv_name)
    TextView mTvName;
    @BindView(R.id.tv_total)
    TextView mTvTotal;
    @BindView(R.id.tv_contact_name)
    TextView mTvContactName;
    @BindView(R.id.tv_contact)
    TextView mTvContact;
    @BindView(R.id.tv_address)
    TextView mTvAddress;
    @BindView(R.id.go_order)
    TextView mGoOrder;

    public static void start(Context context, SalesUserCustomerInfo.Data item) {
        mData = item;
        Intent starter = new Intent(context, CustomerDetail.class);
        context.startActivity(starter);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        addContentView(R.layout.manager_customer_detail);
        initTitle("我的客户");

        setText(mTvContactName, mData.getRealname());
        setText(mTvContact, mData.getMobile());
        setText(mTvAddress, mData.getAddress());

        M.salesUsercustomer_view(mData.getMember_id(), this, new CCallBack<SalesUsercustomer_viewInfo>() {
            @Override
            public void onSuccess(SalesUsercustomer_viewInfo salesUsercustomer_viewInfo) throws Exception {
                SalesUsercustomer_viewInfo.Data data = salesUsercustomer_viewInfo.getData();
                ImgLoader.displayRound(mIvAvatar, data.getAvatar());
                setText(mTvName, data.getCompany());
                setText(mTvTotal, data.getOrder_amount());
            }

            @Override
            public void onFailure(int code, String msg) {
                toast(msg);
            }
        });
    }

    @OnClick(R.id.go_order)
    public void onViewClicked() {
        CustomerOrder.start(getActivity(), mData.getMember_id());
    }
}
